import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { Column, Entity, PrimaryColumn } from 'typeorm';
// materialCode	materialLable	suggestPrice	materialType

export enum MaterialType {
  machine = 'machine',
  tool = 'tool',
  consumable = 'consumable',
}
// Object.keys(MaterialType)  ['machine','tool','consumable']
// Object.values(MaterialType)
//
@Entity({
  name: 'Material',
  synchronize: false,
})
export class Material {
  @ApiProperty({ example: 'MT111000' })
  @Rule(RuleType.string().allow(null).min(0).required())
  @PrimaryColumn({ type: 'varchar', length: 32 })
  materialCode: string;
  @ApiProperty({ example: '游标卡尺' })
  @Rule(RuleType.string().allow(null).min(0).required())
  @Column({ nullable: true })
  materialLable: string;
  @ApiProperty({ example: 20.58 })
  @Rule(RuleType.number().required())
  @Column({
    type: 'float',
  })
  suggestPrice: number;

  @ApiProperty({ example: MaterialType.consumable })
  @Rule(
    RuleType.string()
      .valid(...Object.values(MaterialType))
      .required()
  )
  @Column({
    type: 'enum',
    enum: MaterialType,
    default: MaterialType.consumable,
  })
  materialType: MaterialType;
}
export class MaterialQueryCondition {
  // materialLable: string;
  // materialType: MaterialType;
  @ApiProperty({ example: '天平' })
  @Rule(RuleType.string().allow('').allow(null).required())
  lableLike: string;
  @ApiProperty({ example: Object.values(MaterialType) })
  @Rule(
    RuleType.array()
      .min(0)
      .items(RuleType.string().valid(...Object.values(MaterialType)))
  )
  materialTypes: Array<MaterialType>;
  @ApiProperty({ example: 1 })
  @Rule(RuleType.number().min(1).required())
  pageNum: number;
  @ApiProperty({ example: 3 })
  @Rule(RuleType.number().min(1).required())
  pageSize: number;
}
// entity 字段是字符串      qc  like string
// entity 字段是数字和时间   qc  min max | start end
// entity 字段是枚举类型     qc  array[enum]
export class MaterialDto4Modify {
  @ApiProperty({ example: 40.58 })
  @Rule(RuleType.number().required())
  suggestPrice: number;
  @ApiProperty({ example: MaterialType.consumable })
  @Rule(
    RuleType.string()
      .valid(...Object.values(MaterialType))
      .required()
  )
  materialType: MaterialType;
}
